package icu.javacg.storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import icu.javacg.storage.pojo.Warehouse;
import icu.javacg.storage.service.WarehouseService;
import icu.javacg.storage.mapper.WarehouseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author sky
* @description 针对表【warehouse(仓库表)】的数据库操作Service实现
* @createDate 2023-04-25 08:42:54
*/
@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse>
    implements WarehouseService{
    @Resource
    private WarehouseMapper warehouseMapper;
    @Override
    public Page<Warehouse> MybatisPlugin(int a, int b) {
        Page<Warehouse> page=new Page<>(a,b);
        Page<Warehouse> warehousePage = warehouseMapper.selectPage(page, null);
        return warehousePage;
    }

    @Override
    public int insert(Warehouse w) {
        int insert = warehouseMapper.insert(w);
        return insert;
    }

    @Override
    public List<Warehouse> listnull(){
        LambdaQueryWrapper<Warehouse> queryWrap=new LambdaQueryWrapper<>();
        queryWrap.isNull(Warehouse::getStorageType);
        List<Warehouse> warehouses = warehouseMapper.selectList(queryWrap);
        return warehouses;
    }

    @Override
    public int delete(int id) {
        int i = warehouseMapper.deleteById(id);
        return i;
    }

    @Override
    public List<Warehouse> selectMax() {
        List<Warehouse> warehouses = warehouseMapper.selectOrder();
        Warehouse warehouse = warehouses.get(0);
        Integer capacity = warehouse.getCapacity();
        System.out.println(capacity);
        List<Warehouse> warehouses1 = warehouseMapper.selectMax(capacity);
        return warehouses1;
    }

    @Override
    public List<Warehouse> selcetName(String name) {
        List<Warehouse> warehouses = warehouseMapper.selectName(name);
        return warehouses;
    }
//
    @Override
    public int updataWarehouse(Warehouse w) {
        int i = warehouseMapper.updateById(w);
        return i;
    }

    @Override
    public List<Warehouse> selectAll() {
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        return warehouses;
    }


}




